package com.flyduck.system.controller;

import com.flyduck.common.annotation.IgnoreAuth;
import com.flyduck.common.vo.Result;
import com.flyduck.system.service.SysMenuService;
import com.flyduck.system.vo.menu.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: flyduck-platform
 * @description: 系统:菜单接口
 * @author: flyduck
 * @create: 2021-02-27 10:27
 **/
@Api(tags = "系统:菜单接口")
@RestController
@RequestMapping("/system/sysMenuController")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("获取菜单树列表")
    @PostMapping("/treeList")
    public Result getMenuTreeList(@RequestBody SysMenuTreeReqVO reqVo){
        List<SysMenuTreeRespVO> deptTreeRespVOS =  sysMenuService.getMenuTreeList(reqVo);
        return Result.success(deptTreeRespVOS);
    }

    @IgnoreAuth
    @ApiOperation("获取菜单详情")
    @GetMapping("/detail")
    public Result getMenuDetail(@RequestParam(value = "id",required = true) Long id){
        SysMenuDetailRespVO respVO = sysMenuService.getMenuDetail(id);
        return Result.success(respVO);
    }

    @ApiOperation("新增菜单")
    @PostMapping("/add")
    public Result addUser(@RequestBody @Validated SysMenuAddReqVO reqVo){
        boolean flag = sysMenuService.addMenu(reqVo);
        return Result.success(flag,"新增成功");
    }

    @ApiOperation("编辑菜单")
    @PutMapping("/update")
    public Result updateDept(@RequestBody @Validated SysMenuUpdateReqVO reqVo){
        boolean flag = sysMenuService.updateMenu(reqVo);
        return Result.success(flag,"编辑菜单");
    }

    @ApiOperation("删除菜单")
    @DeleteMapping("/delete")
    public Result deleteMenu(@RequestParam(value = "id",required = true) Long id){
        boolean flag = sysMenuService.deleteMenu(id);
        return Result.success(flag,"删除成功");
    }

    @IgnoreAuth
    @ApiOperation("获取菜单下拉树")
    @GetMapping("/treeSelect")
    public Result getMenuTreeSelect(){
        List<SysMenuTreeSelectRespVO> deptTreeRespVOS =  sysMenuService.getMenuTreeSelect();
        return Result.success(deptTreeRespVOS);
    }

}
